package com.xgk.boot.module.core.controller.admin.channel.vo.sp;

import com.xgk.boot.module.core.dal.entity.channel.ApiServiceDO;
import com.xgk.boot.module.core.dal.entity.channel.ServiceProviderDO;
import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Data
public class SpSelectNode {
    private String id;
    private String title;
    private Boolean isLeaf;
    private String value;
    private List<SpSelectNode> children;

    // 新增字段
    private String path;          // 完整路径 "集团总部/物流事业部/运费计算API"
    private List<String> parentChain; // 父节点ID链 ["sp_1", "sp_2"]

    // 构建供应商节点
    public static SpSelectNode buildProviderNode(ServiceProviderDO provider) {
        SpSelectNode node = new SpSelectNode();
        node.setId("sp_" + provider.getSpId());
        node.setTitle(provider.getSpName());
        node.setIsLeaf(false);
        node.setChildren(new ArrayList<>());
        node.setPath(provider.getSpName()); // 初始化路径
        node.setParentChain(Collections.emptyList()); // 供应商节点没有父级
        node.setValue("sp_" + provider.getSpId());
        return node;
    }

    // 构建API节点
    public static SpSelectNode buildApiNode(ApiServiceDO api, String parentPath, List<String> parentChain) {
        SpSelectNode node = new SpSelectNode();
        node.setId("api_" + api.getAsId());
        node.setTitle(api.getAsName());
        node.setIsLeaf(true);
        node.setPath(parentPath + "/" + api.getAsName()); // 拼接完整路径
        node.setParentChain(parentChain); // 设置父节点链
        node.setValue("api_" + api.getAsId());
        return node;
    }
}